package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.web.bind.annotation.*;

/**
 * @Description SetmealController
 * @Author lyh
 * @Date 2024-09-21
 */
@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐管理")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param dto
     * @return
     */
    @PostMapping
    @ApiOperation("新增套餐")
    @CacheEvict(value="setmeal",allEntries = true)
    public Result<String> save(@RequestBody SetmealDTO dto){
        setmealService.save(dto);
        return Result.success();
    }
    //可以根据需要，按照套餐名称、分类、售卖状态进行查询

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> pageQuery(SetmealPageQueryDTO dto){
     PageResult pageResult=setmealService.pageQuery(dto);
     return Result.success(pageResult);
    }

    /**
     * 根据id查询套餐
     * @param setmealId
     * @return
     */
    @GetMapping("/{setmealId}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Long setmealId){
        SetmealVO setmealVO=setmealService.getById(setmealId);
        return Result.success(setmealVO);
    }

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("批量删除套餐")
    @CacheEvict(value="setmeal",allEntries = true)
    public Result<String> delete(Long[] ids){
       setmealService.delete(ids);
       return Result.success();
    }

    /**
     * 修改套餐
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("修改套餐")
    @CacheEvict(value="setmeal",allEntries = true)
    public Result<String> update(@RequestBody SetmealDTO dto){
        setmealService.update(dto);
        return Result.success();
    }

    /**
     * 禁用启用套餐
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("禁用启用套餐")
    @CacheEvict(value="setmeal",allEntries = true)
   public Result<String> stopOrStart(@PathVariable Integer status,long id){
        setmealService.stopOrStart(status,id);
        return Result.success();
    }
}
